package cn.zhou.basic.controller;

import cn.zhou.basic.dto.LoginDto;
import cn.zhou.basic.dto.WechatDto;
import cn.zhou.basic.service.ILoginService;
import cn.zhou.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private ILoginService loginService;
//    "/login/account"
    @PostMapping("/account")
    public AjaxResult login(@RequestBody LoginDto dto){
        try {
            Map<String, Object> map = loginService.login(dto);
            return new AjaxResult().setResultObj(map);
        }catch( Exception e){
            e.printStackTrace();
            return new AjaxResult().setSuccess(false).setMessage("苏喂苏喂苏喂");
        }

    }
    @PostMapping("/wechat")
    public AjaxResult wechat(@RequestBody WechatDto dto) {
        try {
            return loginService.wechat(dto);
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult().setSuccess(false).setMessage("苏喂苏喂苏喂");
        }
    }
    @PostMapping("/wechat/binder")//wechat/binder
    public AjaxResult binder(@RequestBody WechatDto dto) {
        try {
            Map<String, Object> map = loginService.binder(dto);
            return new AjaxResult().setResultObj(map);
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult().setSuccess(false).setMessage("苏喂苏喂苏喂");
        }
    }
}
